﻿//Copyright (c) Microsoft Corporation.  All rights reserved.

using System;

namespace Microsoft.Ted.Wacel.Base
{
    public abstract class Array<T>: CloudDataStructure
    {
        private long mSize;
        public Array(string name, long size, IDataProvider dataProvider, ILockProvider lockProvider)
            :base(name, dataProvider, lockProvider)
        {
            mSize = size;
        }
        public virtual T this[long key]
        {
            get
            {
                if (key < 0 || key >= mSize)
                    throw new IndexOutOfRangeException();
                object value = Get(key.ToString());
                if (value == null)
                    return default(T);
                else
                    return (T)value;
            }
            set
            {
                if (key < 0 || key >= mSize)
                    throw new IndexOutOfRangeException();
                Put(key.ToString(), value);
            }
        }
        public long Length
        {
            get
            {
                return mSize;
            }
        }
    }
}
